<template>
  <div class="_wz_cent_main _wz_riskManagement">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="80" inline>
        <FormItem label="整改状态">
          <i-select v-model.number="formDataSearch.riskInspectItemHandleState" filterable placeholder="请选择整改状态" clearable>
            <Option :value="0">未整改</Option>
            <Option :value="1">已整改</Option>
          </i-select>
        </FormItem>
        <FormItem label="核查人员">
          <i-input v-model="formDataSearch.riskInspectItemCheckUserName" placeholder="请填写核查人员" clearable />
        </FormItem>
        <FormItem label="核查结果" v-if="searchType">
          <i-select v-model.number="formDataSearch.riskInspectItemCheckLv" filterable placeholder="请选择核查结果" clearable>
            <Option :value="0">无隐患</Option>
            <Option :value="1">一般隐患</Option>
            <Option :value="2">重大隐患</Option>
          </i-select>
        </FormItem>
        <FormItem label="整改人员" v-if="searchType">
          <i-input v-model="formDataSearch.riskInspectItemHandleUserName" placeholder="请填写整改人员" clearable />
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>


    <!--隐患操作-->
    <Drawer :title="formTitle" v-model="operationProcessType" width="1100" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <operationProcess v-if="operationProcessType" @closeFun="closeFun" :selectData="selectData"></operationProcess>
    </Drawer>



    <Drawer title="详情" v-model="formOperation" width="1100" :mask-closable="false" :draggable="true">
      <hiddenDetails v-if="formOperation" :selectData="selectData"></hiddenDetails>
    </Drawer>


    <Drawer title="操作记录" v-model="operationRecordsType" width="700" :mask-closable="false" :draggable="true">
      <operationRecords v-if="operationRecordsType" :selectData="selectData"></operationRecords>
    </Drawer>

  </div>
</template>
<script>


import wzTbale from "../../components/table/table";
import operationProcess from "./operationProcess";
import hiddenDetails from "./hiddenDetails";// hiddenDetails  隐患详情
import operationRecords from "./operationRecords";//操作记录

export default {
  components: {
    wzTbale,//列表
    operationProcess,//操作 处理
    hiddenDetails,//隐患详情
    operationRecords,
  },
  data() {
    return {
      operationRecordsType:false,//操作记录
      formOperation:false,
      formTitle:'',
      operationProcessType:false,//操作处理
      formOperationStyles: {//表单左侧移出css
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },
      searchType:false,//搜索条件
      subDeptList: [],//运输企业
      formDataSearch: {riskInspectItemProcess:3},//搜索表单数据
      selectData: {},
      tableData: {
        url: this.apiUrl.riskInspectRiskInspectItemPageList,//请求地址
        method: 'post',//请求方式
        where: {riskInspectItemProcess:3},//搜索条件
        height: 'auto',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '隐患排查', minWidth: 140, key: 'riskInspectItemName'},
          {title: '整改状态', minWidth: 140, key: 'riskInspectItemHandleState', render: (h, params) => {
              //0：未核查，1：已核查，-1：已退回
              var color = '', test = '';
              if (params.row.riskInspectItemHandleState == 0) {
                color = 'error', test = '未整改';
              } else if (params.row.riskInspectItemHandleState == 1) {
                color = 'primary', test = '已整改';
              } else if (params.row.riskInspectItemHandleState == -1){
                color = 'warning', test = '已退回';
              }
              return h('Tag', {props: {type: 'dot',color: color}}, test);
            }
          },

          // {title: '隐患部位', minWidth: 140, key: 'riskPositionName'},
          // {title: '隐患类型', minWidth: 140, key: 'riskPositionType', render: (h, params) => {
          //     //  （1：基础管理、2：设备设施、3：作业活动）
          //     if (params.row.riskPositionType == 1) {
          //       return h('Tag', {props: {type: 'dot',color: 'success'}}, '基础管理')
          //     } else if (params.row.riskPositionType == 2) {
          //       return h('Tag', {props: {type: 'dot',color: 'primary'}}, '设备设施')
          //     } else if (params.row.riskPositionType == 3) {
          //       return h('Tag', {props: {type: 'dot',color: 'warning'}}, '作业活动')
          //     }
          //   }
          // },
          // {title: '隐患项目', minWidth: 140, key: 'riskPositionItemName'},
          {title: '隐患等级', minWidth: 140, key: 'riskInspectItemLv', render: (h, params) => {
              //0：不是隐患，1：一般隐患，2：重大隐患
              var color = '', test = '';
              if (params.row.riskInspectItemLv == 0) {
                color = 'success', test = '无隐患';
              } else if (params.row.riskInspectItemLv == 1) {
                color = 'warning', test = '一般隐患';
              } else if (params.row.riskInspectItemLv == 2){
                color = 'error', test = '重大隐患';
              } else{
                color = 'error', test = '未排查';
              }
              return h('Tag', {props: {type: 'dot',color: color}}, test);
            }
          },
          {title: '核查结果', minWidth: 140, key: 'riskInspectItemCheckLv', render: (h, params) => {
              //0：不是隐患，1：一般隐患，2：重大隐患
              var color = '', test = '';
              if (params.row.riskInspectItemCheckLv == 0) {
                color = 'success', test = '无隐患';
              } else if (params.row.riskInspectItemCheckLv == 1) {
                color = 'warning', test = '一般隐患';
              } else if (params.row.riskInspectItemCheckLv == 2){
                color = 'error', test = '重大隐患';
              } else{
                color = 'error', test = '未核查';
              }
              return h('Tag', {props: {type: 'dot',color: color}}, test);
            }
          },
          {title: '整改方式', minWidth: 140, key: 'riskInspectItemHandleType', render: (h, params) => {
              //1：立即整改，2：限期整改，2：停业整改
              var color = '', test = '';
              if (params.row.riskInspectItemHandleType == 1) {
                color = 'warning', test = '立即整改';
              } else if (params.row.riskInspectItemHandleType == 2) {
                color = 'success', test = '限期整改';
              } else if (params.row.riskInspectItemHandleType == 3){
                color = 'error', test = '停业整改';
              }
              return h('Tag', {props: {type: 'dot',color: color}}, test);
            }
          },
          {title: '限期整改', minWidth: 120, key: 'riskInspectItemHandleDate'},
          {title: '核查人员', minWidth: 120, key: 'riskInspectItemCheckUserName'},
          {title: '整改人员', minWidth: 120, key: 'riskInspectItemHandleUserName'},
          {title: '整改时间', key: 'riskInspectItemHandleTime', minWidth: 180},
          {title: '运输企业', minWidth: 260, key: 'deptName'},
          {
            title: '操作', fixed: 'right', width: 120,
            render: (h, params) => {
              var operationButtons = [];
              //查看
              operationButtons.push(
                h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.selectData = JSON.parse(JSON.stringify(params.row));
                      this.formOperation = true;
                    }
                  }
                }, "查看")
              )

              if(params.row.riskInspectItemHandleState == 0 || params.row.riskInspectItemReviewState == -1){
                operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                //整改
                operationButtons.push(
                  h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.formTitle = '隐患整改';
                        this.selectData = JSON.parse(JSON.stringify(params.row));
                        this.operationProcessType = true;
                      }
                    }
                  }, "整改")
                )
              }else{
                operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                //记录
                operationButtons.push(
                  h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.selectData = JSON.parse(JSON.stringify(params.row));
                        this.operationRecordsType = true;
                      }
                    }
                  }, "记录")
                )
              }
              return operationButtons;
            }
          },
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
          count: ['count'],//数据总量
        },
      },

    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    var that = this;

    //运输企业
    that.axios.post(that.apiUrl.coreDeptCoreDeptList,{}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })
  },
  methods: {//执行的方法
    searchSubmit() {//搜索
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },
    //添加修改触发后关闭刷新
    closeFun(data) {
      var that = this;
      if (data) {//添加修改 刷新表单
        that.$refs.wzTbale.tableLoadData();
      }
      that.operationProcessType = false;
    },
  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_riskManagement {
  display: flex;
  flex-direction: column;
}
</style>
